local qingjian = fk.CreateSkill {

  name = "joyex__qingjian",

  tags = {  },

}



qingjian:addEffect(fk.AfterCardsMove, {
  name = "joyex__qingjian",
  anim_type = "support",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(qingjian.name) and player:usedSkillTimes(qingjian.name, Player.HistoryTurn) == 0 then
      if event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          if move.to==player and move.toArea == Player.Hand and move.skillName ~= qingjian.name and player.phase ~= Player.Draw then
            return not player:isNude()
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local n = #player:getCardIds("he")
    local cards = player.room:askForCard(player,1,n,true,qingjian.name,true,".","#joyex__qingjian-invoke1")
    if #cards > 0 then
      event:setCostData(self, {cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local n = #player:getCardIds("he")
    local cards = event:getCostData(self)
    local tos = player.room:askForChoosePlayers(player,table.map(player.room:getOtherPlayers(player), Util.IdMapper),1,1,"#joyex__qingjian-invoke2",qingjian.name,false)
    if #tos > 0 then
      local room = player.room
      local to = room:getPlayerById(tos[1])
      player:showCards(cards)
      room:moveCardTo(cards, Player.Hand, to, fk.ReasonGive, qingjian.name, nil, true)
      if not player.dead then
        player:drawCards(1,qingjian.name)
      end
    end
  end,
})

return qingjian